package com.wu.controller.system;

import com.wu.base.ApiResponse;
import com.wu.base.PageInfoData;
import com.wu.controller.BaseController;
import com.wu.pojo.reqeust.sys.ListResourceRequest;
import com.wu.pojo.reqeust.sys.ResourceAllRequest;
import com.wu.pojo.response.sys.ResourceListResponse;
import com.wu.pojo.response.sys.ResourceTreeResponse;
import com.wu.service.sys.SResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author wujilu
 * @since 2020-11-24
 */
@RestController
@Api( tags = "S权限资源相关接口")
@RequestMapping("/resource")
public class SResourceController extends BaseController {

    @Resource
    private SResourceService resourceService;

    @ApiOperation(value = "权限资源 列表")
    @RequiresPermissions("/resource/list")
    @PostMapping(value = "/list")
    public ApiResponse<PageInfoData<ResourceListResponse>> list(@RequestBody ListResourceRequest request) {
        return resourceService.listResource(request);
    }

    @ApiOperation(value = "当前人的权限资源树结构列表")
    @RequiresPermissions("/resource/treeList")
    @PostMapping(value = "/treeList")
    public ApiResponse<ResourceTreeResponse> treeList(@RequestBody ResourceAllRequest request) {
        return resourceService.treeList(request);
    }

    @ApiOperation(value = "权限资源树结构列表，所有")
    @RequiresPermissions("/resource/treeListAll")
    @PostMapping(value = "/treeListAll")
    public ApiResponse<ResourceTreeResponse> treeListAll(@RequestBody ResourceAllRequest request) {
        return resourceService.treeListAll(request);
    }

    @ApiOperation(value = "", hidden = true)
    @PostMapping(value = "/sync")
    public void sync(@RequestBody ResourceAllRequest request) {
        resourceService.sync(request);
    }

}
